package com.qingke;

import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.qingke.pojo.User;

public class DeleteApp {
	
	public static void main(String[] args) {
		String configFile = "mybatis.xml";
		InputStream is = DeleteApp.class.getClassLoader().getResourceAsStream(configFile);
		SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is);
		SqlSession session = sessionFactory.openSession();
		String statement = "com.qingke.mapping.userMapper.updateUser";
		
		User user = new User();
		user.setId(5);
		user.setName("王五");
		
		session.update(statement, user);
		getAllUsers(session);
		
		session.commit();
		session.close();
	}
	
	private static void getAllUsers(SqlSession session) {
		String statement = "com.qingke.mapping.userMapper.getAllUsersByName";
		List<User> list = session.selectList(statement, "lisi");
		for(User user :list) {
			System.out.println(user);
		}
		
	}

}
